<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="24">
            <a-form-model-item label="工种类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kindOfWorkType">
              <a-select
                show-search
                :allowClear="true"
                placeholder="请选择工种类型"
                option-filter-prop="children"
                v-model="queryParam.kindOfWorkType"
                style="width: 100%"
                :filter-option="filterOptionKindOfWorkType"
                @change="changeKindOfWorkType">
                <a-select-option :value="item.id" v-for="(item,index) in kindOfWorkTypeData" :key="index">
                  {{item.kindOfWork}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" style="width: 100%" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoadList"
        >

          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
          >
            <div>
              <div class="name">工种类型名称：{{item.kindOfWorkTypeName || ''}}</div>
              <div class="contact">
                <span>施工部位：{{ item.constructionPlace || '无' }}</span>
              </div>
              <div class="contact">
                <span>工价：{{ item.labourCost || '无' }}</span>
                <span style="margin-left: 20px;">单位：{{ item.unit || '无' }}</span>
                <span style="float: right">
                  <a @click="handleEdit(item)">编辑</a>
                  <a-divider type="vertical" />
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(item.id)">
                    <a>删除</a>
                  </a-popconfirm>
                  <!--<a @click="workInfoDetail(item)">详情</a>-->
                </span>
              </div>
              <div class="contact">
                <span>规格：{{ item.specifications || '无'}}</span>
              </div>
              <div class="contact">
                <span>备注：{{ item.remark || '无'}}</span>
              </div>
            </div>
          </div>
        </van-list>
      </div>
    </div>

    <add-price-management-modal ref="modalForm" @ok="modalFormOk"></add-price-management-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import addPriceManagementModal from "./modules/addPriceManagementModal";
  import {deleteAction} from "../../../../api/manage";

  export default {
    name: 'priceManagementList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      addPriceManagementModal,
    },
    data () {
      return {
        description: '工价管理表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'工种类型名称',
            align:"center",
            dataIndex: 'kindOfWorkTypeName',
            width: '10%',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '10%',
                }
              }
            }
          },
          {
            title:'施工部位',
            align:"center",
            dataIndex: 'constructionPlace',
            width: '10%',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '10%',
                }
              }
            }
          },
          {
            title:'工价',
            align:"center",
            dataIndex: 'labourCost',
            width: '10%',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '10%',
                }
              }
            }
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unit',
            width: '10%',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '10%',
                }
              }
            }
          },
          {
            title:'规格',
            align:"center",
            dataIndex: 'specifications',
            width: '20%',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '20%',
                }
              }
            }
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            width: '30%',
            customCell:() => {
              return {
                style: {
                  wordWrap:'break-word',
                  wordBreak:'break-all',
                  whiteSpace:'normal',
                  minHeight:'50px',
                  width: '30%',
                }
              }
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ghPriceManagement/list",
          delete: "/ghPriceManagement/delete",
          deleteBatch: "/ghPriceManagement/deleteBatch",
          exportXlsUrl: "/ghPriceManagement/exportXls",
          importExcelUrl: "/ghPriceManagement/importExcel",
          queryKindOfWorkTypeList: "/ghKindOfWork/queryList"
        },
        dictOptions:{},
        superFieldList:[],
        kindOfWorkTypeData:[],
        queryParam: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        selectedRowKeys: [],
        selectedRows: [],
        finished: false,
        loading: false,
      }
    },
    created() {
      this.loadKindOfWorkTypeData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //加载工种类型数据
      loadKindOfWorkTypeData(){
        getAction(this.url.queryKindOfWorkTypeList).then((res) => {
          if (res.success) {
            this.kindOfWorkTypeData = res.result.records||res.result;
          }else{
            this.$message.warning(res.message)
          }
        })
      },
      filterOptionKindOfWorkType(input, option){
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      changeKindOfWorkType(value){
        this.loadData(1);
      },
      onSelectAll(selected, selectedRows, changeRows) {
        if(selected) {
          let rows = [...selectedRows]
          this.selectedRows = this.selectedRows.concat(rows)
        } else {
          changeRows.forEach(item => {
            const delIndex = this.selectedRows.findIndex((val) => {
              return val.id === item.id
            })
            this.selectedRows.splice(delIndex, 1)
          })
        }
      },
      onSelect(record, selected) {
        if(selected) {
          this.selectedRows.push(record);
        } else {
          const delIndex = this.selectedRows.findIndex((val) => {
            return val.id === record.id
          })
          this.selectedRows.splice(delIndex,1)
        }
      },
      onSelectChange(selectedRowKeys) {
        this.selectedRowKeys = selectedRowKeys;
      },
      onLoadList(e){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = []
          this.finished = false;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records]
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
          if(res.result.records.length<10){
            this.finished = true;
          }
        }).finally(() => {
          this.loading = false
        })
      },
      modalFormOk(){
        this.loadData(1)
      },
      handleDelete(id) {
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        let that = this;
        that.loading = true;
        deleteAction(that.url.delete, {id: id}).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage(1)
            that.$message.success(res.message);
            that.loadData(1);
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          this.loading = false
        });
      },
    }
  }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';
  .select-pk{
    display:flex;
    align-items:center;
    margin:10px 0;
    &>span{
      font-weight: bold;
    }
    &-text{
      width: calc(100% - 6em);
      height: 30px;
      text-indent: 1em;
      line-height: 28px;
      border: 1px solid #d9d9d9;
      border-radius: 4px;
    }
  }
  .list{
    overflow-y: scroll;
    height:100vh;
    margin-top: 10px;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list{
    /*display: flex;*/
    align-items: center;
    border-top: 1px solid #d9d9d9;
    .name{
      font-size: 13px;
      color: #161616;
      line-height: normal;
      margin-top: 5px;
    }
    .contact{
      margin-top: 5px;
      font-size: 12px;
      color: #a39f9f;
      margin-bottom: 5px;
    }
  }
</style>